65a8fe26905112e4b26a83d6d4260ebaff7c4266,src/edu/stanford/nlp/pipeline/StanfordCoreNLP.java,StanfordCoreNLP,getDefaultAnnotatorPool,#Properties#,301

Before Change


    //
    // Post-processing tokenization rules for the NFL domain
    //
    pool.register(STANFORD_NFL_TOKENIZE, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        final String className =
          "edu.stanford.nlp.pipeline.NFLTokenizerAnnotator";
        return ReflectionLoading.loadByReflection(className);
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        // no used props for this one
        return "";
      }
    });

    //
    // Entity and relation extraction for the NFL domain
    //
    pool.register(STANFORD_NFL, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        // these paths now extracted inside c'tor
        // String gazetteer = properties.getProperty("nfl.gazetteer", DefaultPaths.DEFAULT_NFL_GAZETTEER);
        // String entityModel = properties.getProperty("nfl.entity.model", DefaultPaths.DEFAULT_NFL_ENTITY_MODEL);
        // String relationModel = properties.getProperty("nfl.relation.model", DefaultPaths.DEFAULT_NFL_RELATION_MODEL);
        final String className = "edu.stanford.nlp.pipeline.NFLAnnotator";
        return ReflectionLoading.loadByReflection(className, properties);
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        return "nfl.verbose:" +
                properties.getProperty("nfl.verbose",
                        "false") +
                "nfl.relations.use.max.recall:" +
                properties.getProperty("nfl.relations.use.max.recall",
                        "false") +
                "nfl.relations.use.model.merging:" +
                properties.getProperty("nfl.relations.use.model.merging",
                        "false") +
                "nfl.relations.use.basic.inference:" +
                properties.getProperty("nfl.relations.use.basic.inference",
                        "true") +
                "nfl.gazetteer:" +
                properties.getProperty("nfl.gazetteer",
                        DefaultPaths.DEFAULT_NFL_GAZETTEER) +
                "nfl.entity.model:" +
                properties.getProperty("nfl.entity.model",
                        DefaultPaths.DEFAULT_NFL_ENTITY_MODEL) +
                "nfl.relation.model:" +
                properties.getProperty("nfl.relation.model",
                        DefaultPaths.DEFAULT_NFL_RELATION_MODEL);
      }
    });

    //
    // Parser
    //
    pool.register(STANFORD_PARSE, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        String parserType = properties.getProperty("parse.type", "stanford");
        String maxLenStr = properties.getProperty("parse.maxlen");

        if (parserType.equalsIgnoreCase("stanford")) {
          ParserAnnotator anno = new ParserAnnotator("parse", properties);
          return anno;
        } else if (parserType.equalsIgnoreCase("charniak")) {
          String model = properties.getProperty("parse.model");
          String parserExecutable = properties.getProperty("parse.executable");
          if (model == null || parserExecutable == null) {
            throw new RuntimeException("Both parse.model and parse.executable properties must be specified if parse.type=charniak");
          }
          int maxLen = 399;
          if (maxLenStr != null) {
            maxLen = Integer.parseInt(maxLenStr);
          }

          CharniakParserAnnotator anno = new CharniakParserAnnotator(model, parserExecutable, false, maxLen);

          return anno;
        } else {
          throw new RuntimeException("Unknown parser type: " + parserType + " (currently supported: stanford and charniak)");
        }
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        String type = properties.getProperty("parse.type", "stanford");
        if(type.equalsIgnoreCase("stanford")){
          return ParserAnnotator.signature("parser", properties);
        } else if(type.equalsIgnoreCase("charniak")) {
          return "parse.model:" +
                  properties.getProperty("parse.model", "") +
                  "parse.executable:" +
                  properties.getProperty("parse.executable", "") +
                  "parse.maxlen:" +
                  properties.getProperty("parse.maxlen", "");
        } else {
          throw new RuntimeException("Unknown parser type: " + type +
                  " (currently supported: stanford and charniak)");
        }
      }
    });

    //
    // Coreference resolution
    //
    pool.register(STANFORD_DETERMINISTIC_COREF, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        return new DeterministicCorefAnnotator(properties);
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        return DeterministicCorefAnnotator.signature(properties);
      }
    });

    // add annotators loaded via reflection from classnames specified
    // in the properties
    for (Object propertyKey : inputProps.stringPropertyNames()) {
      if (!(propertyKey instanceof String))
        continue; // should this be an Exception?
      String property = (String) propertyKey;
      if (property.startsWith(CUSTOM_ANNOTATOR_PREFIX)) {
        final String customName =
          property.substring(CUSTOM_ANNOTATOR_PREFIX.length());
        final String customClassName = inputProps.getProperty(property);
        System.err.println("Registering annotator " + customName +
            " with class " + customClassName);
        pool.register(customName, new AnnotatorFactory(inputProps) {
          private static final long serialVersionUID = 1L;
          private final String name = customName;
          private final String className = customClassName;
          @Override
          public Annotator create() {
            return ReflectionLoading.loadByReflection(className, name,
                                                      properties);
          }
          @Override
          public String signature() {
            // keep track of all relevant properties for this annotator here!
            // since we don't know what props they need, let's copy all
            // TODO: can we do better here? maybe signature() should be a method in the Annotator?
            StringBuilder os = new StringBuilder();
            for(Object key: properties.keySet()) {
              String skey = (String) key;
              os.append(skey + ":" + properties.getProperty(skey));
            }
            return os.toString();
          }
        });
      }
    }


    pool.register(STANFORD_RELATION, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        final String className = "edu.stanford.nlp.pipeline.RelationExtractorAnnotator";
        return ReflectionLoading.loadByReflection(className, properties);
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        return "TODO";
      }
    });
    
    //
    // add more annotators here!

After Change


    }


    pool.register(STANFORD_RELATION, new AnnotatorFactory(inputProps) {
      private static final long serialVersionUID = 1L;
      @Override
      public Annotator create() {
        return new RelationExtractorAnnotator(properties);
      }

      @Override
      public String signature() {
        // keep track of all relevant properties for this annotator here!
        return "sup.relation.verbose:" +
        properties.getProperty("sup.relation.verbose",
                "false") +
        properties.getProperty("sup.relation.model",
                DefaultPaths.DEFAULT_SUP_RELATION_EX_RELATION_MODEL);
      }
    });
    
    //
    // add more annotators here!